package com.learn.aop.aspects;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Order(5)
public class TxAspect {

    @Around(value = "com.learn.aop.aspects.LogAspect1.transactionPointCut()")
    public Object manageTransaction(ProceedingJoinPoint joinPoint) {

        Object[] args = joinPoint.getArgs();
        Object returnValue = null;
        try {
            System.out.println(joinPoint.getSignature().getName() + "开启事务");
            returnValue = joinPoint.proceed(args);
            System.out.println("返回值" + returnValue);
        } catch (Throwable e) {
            System.out.println("异常信息" + e.getClass().getName());
            System.out.println(joinPoint.getSignature().getName() + "回滚事务");
        } finally {
            System.out.println(joinPoint.getSignature().getName() + "提交事务");
        }
        return returnValue;
    }
}
